package com.xianbeiying.app.ckgl.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.xianbeiying.app.ckgl.R;
import com.xianbeiying.app.ckgl.adapter.CounselListdapter;
import com.xianbeiying.app.ckgl.bean.CollectBean;
import com.xianbeiying.app.ckgl.http.HttpCallBackUtil;
import com.xianbeiying.app.ckgl.model.SetModel;
import com.xianbeiying.app.ckgl.util.ToastUtil;
import com.xianbeiying.app.ckgl.widght.NoScrollListView;

/**
 * 详情正文
 * */
public class CounselDetailActivity extends BaseActivity  implements HttpCallBackUtil,View.OnClickListener{
    private ImageView iv_title_left;
    private TextView tv_title;
    private ImageView iv_shared,iv_collect;
    private TextView tv_cd_title,tv_cd_source,tv_cd_content;
    private ImageView img_cd;
    private NoScrollListView counseldetail_list;
    private CounselListdapter counselListAdapter;
    private ScrollView counsel_scroll;
    private SetModel setModel;
    private ImageLoader imageLoader=ImageLoader.getInstance();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_counsel_detail);
        initView();
    }
    private void initView(){
        counsel_scroll=(ScrollView) findViewById(R.id.counsel_scroll);
        iv_title_left = (ImageView) findViewById(R.id.iv_title_left);
        iv_shared = (ImageView) findViewById(R.id.iv_shared);
        iv_collect = (ImageView) findViewById(R.id.iv_collect);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_cd_title = (TextView) findViewById(R.id.tv_cd_title);
        tv_cd_source = (TextView) findViewById(R.id.tv_cd_source);
        tv_cd_content = (TextView) findViewById(R.id.tv_cd_content);
        img_cd = (ImageView) findViewById(R.id.img_cd);
        counseldetail_list = (NoScrollListView) findViewById(R.id.counseldetail_list);
        counsel_scroll.smoothScrollBy(0,0);
        setModel=new SetModel(this);
        setModel.addResponseListener(this);
        initData();
        initEvent();
    }
    private void initData(){
        tv_title.setText("详情正文");
        counselListAdapter=new CounselListdapter(this);
        counseldetail_list.setAdapter(counselListAdapter);
        MainActivity.fragmentid=1;
    }
    private void initEvent(){
        iv_title_left.setOnClickListener(this);
        iv_shared.setOnClickListener(this);
        iv_collect.setOnClickListener(this);
    }
    private CollectBean collectBean;
    @Override
    public void onCallBackData(String url, Object content) {
         //添加收藏
        if(url.equals("添加收藏")){
            if(content!=null){
                collectBean= JSON.parseObject(new String((byte []) content),CollectBean.class);
                if(collectBean.isR()){
                    iv_collect.setSelected(true);
                    ToastUtil.showInfo(CounselDetailActivity.this,"收藏成功");
                }else{
                    ToastUtil.showInfo(CounselDetailActivity.this,collectBean.getERR_MSG());
                }
            }
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_title_left:
                finish();
                break;
            //收藏
            case R.id.iv_collect:
//                setModel.ADDCOLLECT("",2222,"333",true);
                break;
            //分享
            case R.id.iv_shared:
                break;

        }
    }
}
